package com.somsoft.bzfk;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.DisplayMetrics;

import com.somsoft.bzfk.common.GameInfo;
import com.somsoft.bzfk.common.MyApplication;
import com.umeng.analytics.MobclickAgent;

public class GameActivity extends Activity {

	DisplayMetrics dm;

	//主线程的Handler对象
		Handler myHandler = new Handler(){
			@Override
			public void handleMessage(Message msg) {//重写处理消息方法
				if(msg.what==0){
					gohome();
				}
			}		
		};
		
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		MyApplication.getInstance().addActivity(this);
		dm = new DisplayMetrics();
		getWindowManager().getDefaultDisplay().getMetrics(dm);

		int level = getIntent().getIntExtra("lv", 1);
		String ppi = dm.widthPixels + "x" + dm.heightPixels;
		GameInfo gi = new GameInfo();
		if(dm.widthPixels<320 || dm.heightPixels<480){
			Intent it = new Intent(this,FailActivity.class);
			startActivity(it);
			finish();
		}else {
			if("320x480".equals(ppi)){
				gi = new GameInfo(23.5f, 0f, 378f, 296.5f, 21, ppi,dm.widthPixels,dm.heightPixels,83,76,level);
			}else if("480x800".equals(ppi)) {
				gi = new GameInfo(12.5f, 0f, 467.5f, 630f, 35, ppi,dm.widthPixels,dm.heightPixels,125,110,level);
			}else if("540x960".equals(ppi)){
				gi = new GameInfo(10f, 0f, 530f, 720f, 40, ppi,dm.widthPixels,dm.heightPixels,140,130,level);
			}else if("720x1280".equals(ppi)){
				gi = new GameInfo(2.5f, 0f, 717.5f, 990f, 55, ppi,dm.widthPixels,dm.heightPixels,187,172,level);
			}else{
				gi = new GameInfo(12.5f, 0f, 467.5f, 630f, 35, "480x800",480,800,125,110,level);
			}
			setContentView(new GameView(this, gi));
		}
	}
	
	private void gohome(){
		Intent it = new Intent(this,WelcomeActivity.class);
		startActivity(it);
		finish();
	}
	
	public void onResume() {
	    super.onResume();
	    MobclickAgent.onResume(this);
	}
	public void onPause() {
	    super.onPause();
	    MobclickAgent.onPause(this);
	}
}